//
//  CKBaseNavController.m
//  FreshBee
//
//  Created by chenkai on 16/10/15.
//  Copyright © 2016年 iOS013. All rights reserved.
//

#import "CKBaseViewController.h"

@interface CKBaseViewController ()

@end

@implementation CKBaseViewController
#pragma mark
#pragma mark 懒加载子控件:
- (UINavigationBar *)navBar{
    if(!_navBar){
        UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
        _navBar = navbar;
        [self.view addSubview:navbar];
        
        //navBar添加下边线:
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, -1)];
        [view setBackgroundColor: [UIColor grayColor]];
        [navbar addSubview:view];
    }
    return _navBar;
}

- (UINavigationItem *)navItem{
    if(!_navItem){
        UINavigationItem *item = [[UINavigationItem alloc]init];
        _navItem = item;
        item.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"v2_goback"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
    }
    return _navItem;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setMyNavBar];
    [self.view bringSubviewToFront:self.navBar];
    
    [[UIApplication sharedApplication].keyWindow setBackgroundColor:[UIColor whiteColor]];
    
}

- (void)setMyNavBar{
    [self.navBar pushNavigationItem:self.navItem animated:NO];

    
}

- (void)popViewController{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navBar.translucent = NO;
    self.navigationController.navigationBar.frame = CGRectZero;
    [self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];

}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navBar.translucent = YES;
    
}






@end
